﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Krypton.Toolkit;
using TSNPro.Data;

namespace TSNPro.MyControl
{
    public partial class StandardMeasureControl : UserControl
    {
        private readonly BindingList<StandardSample> _sampleList;
        public StandardMeasureControl()
        {
            InitializeComponent();

            ConfigureDataGridView(dgvStandardSample);
            _sampleList = new BindingList<StandardSample>
            {
                new StandardSample
                {
                    StandardName = "Sample 1",
                    ElementType = ElementType.S,
                    ElementState = ElementState.Liquid,
                    Concentration = 0.5,
                    InSampleVolume = 100,
                    BlankIntegral = 150
                },
                new StandardSample
                {
                    StandardName = "Sample 2",
                    ElementType = ElementType.N,
                    ElementState = ElementState.Gas,
                    Concentration = 0.3,
                    InSampleVolume = 80,
                    BlankIntegral = 130
                }
            };
            dgvStandardSample.DataSource = _sampleList;

            InitPlot();
        }

        private void InitPlot()
        {
            plotIntegra.Plot.Title("积分值");
            plotFit.Plot.Title("拟合结果");
            plotIntegra.Render();
            plotFit.Render();
        }

        private void ConfigureDataGridView(DataGridView dataGridView1)
        {
            // 清空默认列
            dataGridView1.Columns.Clear();
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            dataGridView1.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;

            // 添加设备名列（文本列）
            dataGridView1.Columns.Add(new KryptonDataGridViewTextBoxColumn
            {
                Name = "StandardName",
                HeaderText = "样品名称",
                DataPropertyName = "StandardName" // 绑定到 StandardSample 的 StandardName 属性
            });

            // 添加元素类型列（ComboBox列）
            KryptonDataGridViewComboBoxColumn elementTypeColumn = new KryptonDataGridViewComboBoxColumn
            {
                Name = "ElementType",
                HeaderText = "元素类型",
                DataSource = Enum.GetValues(typeof(ElementType)), // 获取枚举值作为数据源
                DataPropertyName = "ElementType",
                DropDownStyle = ComboBoxStyle.DropDownList
            };
            dataGridView1.Columns.Add(elementTypeColumn);

            // 添加元素状态列（ComboBox列）
            KryptonDataGridViewComboBoxColumn elementStateColumn = new KryptonDataGridViewComboBoxColumn
            {
                Name = "ElementState",
                HeaderText = "元素状态",
                DataSource = Enum.GetValues(typeof(ElementState)), // 获取枚举值作为数据源
                DataPropertyName = "ElementState",
                DropDownStyle = ComboBoxStyle.DropDownList
            };
            dataGridView1.Columns.Add(elementStateColumn);

            // 添加浓度列（文本列）
            dataGridView1.Columns.Add(new KryptonDataGridViewNumericUpDownColumn
            {
                Name = "Concentration",
                HeaderText = "元素浓度",
                DecimalPlaces = 2,
                DataPropertyName = "Concentration" // 绑定到 StandardSample 的 Concentration 属性
            });

            // 添加进样量列（文本列）
            dataGridView1.Columns.Add(new KryptonDataGridViewNumericUpDownColumn
            {
                Name = "InSampleVolume",
                HeaderText = "进样量uL",
                DecimalPlaces = 2,
                DataPropertyName = "InSampleVolume" // 绑定到 StandardSample 的 InSampleVolume 属性
            });

            // 添加空白积分列（文本列）
            dataGridView1.Columns.Add(new KryptonDataGridViewNumericUpDownColumn
            {
                Name = "BlankIntegral",
                HeaderText = "空白积分",
                DecimalPlaces = 2,
                DataPropertyName = "BlankIntegral" // 绑定到 StandardSample 的 BlankIntegral 属性
            });
        }
    }
}
